package com.hzy.fivepalace.wx.controller.api;

import com.hzy.fivepalace.common.page.TableDataInfo;
import com.hzy.fivepalace.db.domain.DtsOrder;
import com.hzy.fivepalace.wx.annotation.LoginUser;
import com.hzy.fivepalace.wx.controller.base.BaseController;
import com.hzy.fivepalace.wx.service.WxGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * 商品类目服务
 */
@RestController
@RequestMapping("/wx/goods")
@Validated
@Api(tags = "商品服务")
public class WxGoodsController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(WxGoodsController.class);

    @Autowired
    private WxGoodsService wxGoodsService;

    /**
     * 首页类目列表
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/getCategoryList")
    @ApiOperation(value = "首页类目列表")
    public TableDataInfo getCategoryList(
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page,
            @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "100") Integer size) {
        return wxGoodsService.getCategoryList(page, size);
    }

    /**
     * 新类目列表
     *
     * @return
     */
    @GetMapping("/getNewCategoryList")
    @ApiOperation(value = "新类目列表")
    public Object getNewCategoryList() {
        return wxGoodsService.getNewCategoryList();
    }


    /**
     * 根据类目id获取商品列表
     *
     * @param orderBy
     * @param categoryId
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/getGoodsListByCategoryId")
    @ApiOperation(value = "根据类目id获取商品列表")
    public TableDataInfo getGoodsListByCategoryId(
            @ApiParam(value = "排序方式:0综合，1销量，2上市新品，3价格由低到高,4价格由高到低,默认为0", defaultValue = "0") @RequestParam(defaultValue = "0") Integer orderBy,
            @ApiParam(value = "类目ID") @NotNull Integer categoryId,
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page,
            @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size) {


        return wxGoodsService.getGoodsListByCategoryId(page, size, categoryId, orderBy);
    }

    /**
     * 根据类目id获取所有商品列表
     * @param categoryId
     * @return
     */
    @GetMapping("/getAllGoodsListByCategoryId")
    @ApiOperation(value = "根据类目id获取所有商品列表")
    public Object getAllGoodsListByCategoryId(@ApiParam(value = "类目ID") @NotNull Integer categoryId) {

        return wxGoodsService.getAllGoodsListByCategoryId(categoryId);
    }


    /**
     * 商品搜索
     *
     * @param content
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/goodsSearch")
    @ApiOperation(value = "商品搜索")
    public TableDataInfo goodsSearch(
            @ApiParam(value = "类目ID") @RequestParam(value = "categoryId", required = false) Integer categoryId,
            @ApiParam(value = "排序方式:0综合，1销量，2上市新品，3价格由低到高,4价格由高到低,默认为0", defaultValue = "0") @RequestParam(defaultValue = "0") Integer orderBy,
            @ApiParam(value = "检索内容") @RequestParam(value = "content", required = false) String content,
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page,
            @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size) {


        return wxGoodsService.goodsSearch(page, size, content, orderBy,categoryId);
    }

    /**
     * 商品详情
     *
     * @param userId
     * @param goodsId
     * @return
     */
    @SuppressWarnings("rawtypes")
    @GetMapping("/detail")
    @ApiOperation(value = "商品详情")
    public Object detail(@LoginUser(login = false) @ApiParam(hidden = true) Integer userId,
                         @ApiParam(value = "商品ID") @NotNull Integer goodsId) {
        return wxGoodsService.detail(userId, goodsId);
    }

    /**
     * 商品详情
     *
     * @param userId
     * @param goodsId
     * @return
     */
    @SuppressWarnings("rawtypes")
    @GetMapping("/detailByGroup")
    @ApiOperation(value = "商品详情")
    public Object detailByGroup(@LoginUser(login = false) @ApiParam(hidden = true) Integer userId,
                         @ApiParam(value = "商品ID") @NotNull Integer goodsId,
                         @ApiParam(value = "拼团ID") @NotNull Integer groupId) {

        return wxGoodsService.detailByGroup(userId, goodsId, groupId);
    }

    /**
     * 商品评价列表
     *
     * @param goodsId
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/commentsList")
    @ApiOperation(value = "商品评价列表")
    public TableDataInfo list(@ApiParam(value = "商品ID") @NotNull Integer goodsId,
                              @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page,
                              @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size) {

        return wxGoodsService.getCommentList(goodsId, page, size);
    }


    /**
     * 热卖推荐
     *
     * @param goodsId
     * @return
     */
    @GetMapping("/sellingRecommend")
    @ApiOperation(value = "热卖推荐")
    public Object sellingRecommend(@ApiParam(value = "所在的商品id") @NotNull Integer goodsId, @LoginUser(login = false) @ApiParam(hidden = true) Integer userId) {
        return wxGoodsService.sellingRecommend(userId, goodsId);
    }

    /**
     * 猜你喜欢
     *
     * @param goodsId
     * @return
     */
    @GetMapping("/guessYouLike")
    @ApiOperation(value = "猜你喜欢")
    public Object guessYouLike(@ApiParam(value = "所在的商品id") @NotNull Integer goodsId, @LoginUser(login = false) @ApiParam(hidden = true) Integer userId) {
        return wxGoodsService.guessYouLike(userId, goodsId);
    }

}
